﻿#region License
//------------------------------------------------------------
// Copyright (c) Denis Vuyka.  All rights reserved.
// This source code is subject to terms and conditions of the 
// Microsoft Reciprocal License (Ms-RL) License for Carcass. 
// A copy of the license can be found in the License.txt file 
// at the root of this distribution. 
// By using this source code in any fashion, you are agreeing 
// to be bound by the terms of the 
// Microsoft Reciprocal License (Ms-RL) License
// You must not remove this notice from this software.
//------------------------------------------------------------
#endregion

using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Carcass.Contents;

namespace DemoShell.Modules.TextDocument
{
  [Export(Carcass.GlobalContracts.DocumentView)]
  [ExportMetadata("DisplayName", "Plain Text View")]
  [ExportMetadata("DocumentType", DocumentTypes.TextFile, IsMultiple = true)]
  [CompositionOptions(CreationPolicy = CreationPolicy.NonShared)]
  public class TextDocumentView : TextBox, IDocumentView
  {
    public TextDocumentView()
    {
      this.TextWrapping = TextWrapping.Wrap;
      this.AcceptsReturn = true;
    }

    public void LoadDocument(IDocument document)
    {
      Binding binding = new Binding
      {
        Source = document,
        Mode = BindingMode.TwoWay,
        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
        Path = new PropertyPath("Text")
      };

      this.SetBinding(TextBox.TextProperty, binding);
    }
  }
}
